<?php
namespace App\Services\Admin;

use Facades\ {
    App\Repositories\Eloquent\AwardRepository,
    App\Repositories\Eloquent\ConstructionRepository,
    Yajra\DataTables\Html\Builder
};
use App\Repositories\Traits\DatatableActionButtonTrait;
use DataTables;
use Exception;

class ArchivesService {
	
	use DatatableActionButtonTrait;

	protected $module = 'archives';

	protected $indexRoute = 'archives.index';

	protected $createRoute = 'archives.create';

	protected $showRoute = 'archives.show';

	protected $editRoute = 'archives.edit';

	protected $destroyRoute = 'archives.destroy';

	/**
	 * datatable数据
	 * @author yinni
	 * @date   2017-11-06
	 * @return [type]     [description]
	 */
	public function ajaxData()
	{
		$awards_data =  AwardRepository::all()->toArray();
		$awards_data_new = [];
		$user_id = auth()->user()->id;
		foreach ($awards_data as $key => $value) {
			if ($awards_data[$key]['user_id'] == $user_id) {
				array_push($awards_data_new, $awards_data[$key]);
			}
		}
		return Datatables::of($awards_data_new)->make(true);
	}

	public function ajaxConstrData() {
		$constrData = ConstructionRepository::all()->toArray();
		$constrDataNew = [];
		$jobnumber = auth()->user()->jobnumber;
		foreach ($constrData as $key => $value) {
			if ($constrData[$key]['jobnumber'] == $jobnumber) {
				array_push($constrDataNew, $constrData[$key]);
			}
		}
		return Datatables::of($constrDataNew)->make(true);
	}
	/**
	 * 重写datatable action按钮
	 * @author yinni
	 * @date   2017-11-06
	 * @param  [type]     $id [description]
	 * @return [type]         [description]
	 */
	public function getActionButtonAttribute($id)
	{
		return $this->getShowActionButtion($id).
				$this->getEditActionButton($id).
				$this->getDestroyActionButton($id);
	}

	// 修改当前上传的获奖信息
	public function edit($id) {
		
	}
	
}